package com.acme;

import java.lang.annotation.Annotation;
import java.lang.reflect.*;

public class Analyzer {

    @SuppressWarnings({ "rawtypes" })
    public static void main(final String[] args) {
	Class clazz = Test.class;
	System.out.println("class name:\n\t" + clazz.getName());

	int modifiers = clazz.getModifiers();
	System.out.println("class modifiers:");
	if (Modifier.isAbstract(modifiers)) {
	    System.out.println("\tabstract");
	}
	if (Modifier.isFinal(modifiers)) {
	    System.out.println("\tfinal");
	}
	if (Modifier.isInterface(modifiers)) {
	    System.out.println("\tinterface");
	}

	System.out.println("package:\n\t" + clazz.getPackage().getName());
	System.out.println("class hierarchy:");
	System.out.println("\t" + clazz.getName());
	Class superclass;
	do {
	    superclass = clazz.getSuperclass();
	    System.out.println("\t" + superclass.getName());
	} while (!superclass.equals(Object.class));

	System.out.println("interfaces:");
	for (Class interf : clazz.getInterfaces()) {
	    System.out.println("\t" + interf.getName());
	}

	System.out.println("fields:");
	for (Field field : clazz.getFields()) {
	    System.out.println("\t" + field.getName());
	    System.out.println("\t\ttype: " + field.getType().getName());
	}

	System.out.println("methods:");
	for (Method method : clazz.getMethods()) {
	    System.out.println("\t" + method.getName());
	    System.out.println("\t\tparameters:");
	    for (Class param : method.getParameterTypes()) {
		System.out.println("\t\t\t" + param.getName());
	    }
	    System.out.println("\t\tannotations:");
	    for (Annotation annotation : method.getAnnotations()) {
		System.out.println("\t\t\t" + annotation);
	    }
	    System.out.println("\t\texceptions:");
	    for (Class exception : method.getExceptionTypes()) {
		System.out.println("\t\t\t" + exception.getName());
	    }
	}
    }
}
